package com.zsrt.javaweb.bbu.department.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.zsrt.javaweb.bbu.department.dao.DepartmentDao;
import com.zsrt.javaweb.bbu.department.entity.DepartmentEntity;

@Repository
public class DepartmentDaoImpl implements DepartmentDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public DepartmentEntity findById(Integer id) {
		String sql = "select id, department_name as departmentName from bbu_department_t where id =?";
		// 行映射 数据库中的1行记录对应java中的一个对象 如何映射结果集中的行 常用的实现类为BeanPropertyRowMapper
		// 通过别名实现列和属性的映射[一一对应] department_name as departmentName
		RowMapper<DepartmentEntity> rowMapper = new BeanPropertyRowMapper<DepartmentEntity>(DepartmentEntity.class);
		DepartmentEntity entity = jdbcTemplate.queryForObject(sql, rowMapper, id);
		return entity;
	}

}
